package com.example

import scala.collection.mutable.ListBuffer
import scala.io.{BufferedSource, Source}

/**
 * 用户位置时长统计
 *
 * @author lbq
 * @date 2022/1/6 23:47
 * @version 1.0
 */

object HomeWork3 {
  def main(args: Array[String]): Unit = {
    val source: BufferedSource = Source.fromFile("src/text.txt")
    val lines = source.getLines()

    val listBuffer = new ListBuffer[(String, String, Int, Int)]()
    while (lines.hasNext) {
      val str = lines.next()
      val data = str.split(" ")
      data.foreach(s => {
        val str = s.split(",")
        listBuffer.addOne((str(0), str(1), str(2).toInt, str(3).toInt))
      })
    }
    source.close()

    val result = listBuffer.map(x => ((x._1, x._2), x._3, x._4)).groupBy(_._1).map {
      case (key, value) => value.reduce((x, y) => (x._1, math.min(x._2, y._2), x._3 + y._3))
    }
    println(result.toString())


  }
}
